/**
 * warning: make sure loaded jquery before Mask.js!
 * step:
 *  1. set Mask.imgPosition = imgFolderPath
 *  	make sure waitMask.gif is in imgFolderPath!
 *  2. use the follow functions:
 * 		a. Mask.Loading()
 * 			show the loading layer.
 * 		b. Mask.Div(divId, titleMsg)
 * 			show your div in layer.
 * 			if tag [<input />] in your div, surround it by div in IE6.
 * 			eg: <div id="mydiv"></div>
 * 				Mask.Div(mydiv, "this is my div");
 * 		c. Mask.Download(filepath)
 * 			show a link in layer, click the link to download file.
 * 			eg: Mask.Download("C:\myfile.txt");
 * 		d. Mask.Message(msg, titleMsg)
 * 			show your message in layer.
 * 			eg: Mask.Message("hello world", "this is my message");
 * 		e. Mask.Close()
 * 			close the current layer.
 * 		f. Mask.Background()
 * 			background of the layer, it will hold screen.
 * 			can't hold full screen under ie 6.
 **/
var Mask = {
		imgPosition : "../assets/css/images",
		divs : [],
		Loading: function(){
			Mask.Reset();
			$("#Mask_maskCenter").css("background-image",
					"url("+Mask.imgPosition+"/waitMask.gif)");
			$("#Mask_maskStatus").text("operating......");

			$("#Mask_maskBgDiv").show();
			$("#Mask_maskDialogDiv").show();
		},
		Div: function(divId, titleMsg) {
			Mask.Reset();
			$("#Mask_maskStatus").text(titleMsg);
			Mask.divs.push(divId);
			$("#"+divId).addClass("Mask_class");
			$("#"+divId).show();

			$("#Mask_maskBgDiv").show();
			$("#Mask_maskDialogDiv").show();
		},
		Download: function(filepath) {
			Mask.Reset();
			$("#Mask_maskDownload").show();
			$("#Mask_maskStatus").text("download");
			$("#Mask_maskAddress").attr("href", filepath);

			$("#Mask_maskBgDiv").show();
			$("#Mask_maskDialogDiv").show();
		},
		Background: function() {
			$("#Mask_maskBgDiv").show();
			$("#Mask_maskDialogDiv").hide();
		},
		Message: function(msg, titleMsg) {
			Mask.Reset();
			$("#Mask_maskStatus").text(titleMsg);
			$("#Mask_maskDownload").hide();
			$("#Mask_maskMsg").text(msg).show();

			$("#Mask_maskBgDiv").show();
			$("#Mask_maskDialogDiv").show();
		},
		Close: function() {
			Mask.Reset();
			Mask.divs = [];
			$("#Mask_maskBgDiv").hide();
			$("#Mask_maskDialogDiv").hide();
		},
		Reset: function(){
			for (var i=0, m=Mask.divs, n=m.length; i<n; i++) {
				$("#"+m[i]).hide();
			}
			$("#Mask_maskCenter").css("background-image",
			"none");
			$("#Mask_maskMsg").hide();
			$("#Mask_maskDownload").hide();
		}
	};

document.write('<div id="Mask_maskBgDiv"></div>\
<div id="Mask_maskDialogDiv" style="display:none">\
	<h2>\
		<span id="Mask_maskStatus">operating......</span>\
		<div id="Mask_maskClose" onclick="Mask.Close()">×</div>\
	</h2>\
	<div id="Mask_maskCenter">\
		<div id="Mask_maskMsg" align="center" style="display:none"></div>\
		<div id="Mask_maskDownload" style="display:none">\
		<a href=# id="Mask_maskAddress" target="_Blank" style="position:center" >right click here and press "save as" to download file</a>\
		</div>\
	</div>\
</div>');
document.write('<style>#Mask_maskBgDiv{\
	background-color:#e3e3e3;\
	position:absolute;\
	z-index:99;\
	top:0; display:none;\
	width:100%;\
	height:100%;\
	opacity:0.5;\
	filter: alpha(opacity=50);\
	-moz-opacity: 0.5;\
}\
#Mask_maskDialogDiv{\
	margin-top:60px;\
	position:absolute;\
	width:400px;\
	left:50%;\
	top:150px;\
	margin-left:-200px;\
	height:auto;\
	z-index:100;\
	background-color:#fff;\
	border:1px solid #8FA4F5;\
	padding:1px;\
}\
#Mask_maskDialogDiv h2{\
	margin-top:0px;\
	height:25px;\
	font-size:14px;\
	background:#7D7DFF url(common/img/title.png) top repeat-x; \
	position:relative;\
	padding-left:10px;\
	line-height:25px;\
	}\
#Mask_maskCenter{\
	padding:40px;\
	background-repeat:no-repeat;\
	border:1px solid #fff;\
	background-position:center center;\
	}\
.Mask_class{\
	position:absolute;\
	width:372px;\
	left:50%;\
	top:180px;\
	margin-left:-200px;\
	height:auto;\
	min-height:95px;\
	_height:95px;\
	padding:15px;\
	z-index:101;\
	background-color:#fff;\
	border:1px solid #8FA4F5;\
	border-top:0;\
	display:none;\
}\
#Mask_maskClose{\
	cursor:pointer;\
	border:0px;\
	width:30px;\
	text-align:center;\
	float:right;\
	margin:0 0 auto;\
	_margin:-25px 0 auto;\
	*margin:-25px 0 auto;\
}</style>');
// for ie6
$(function(){
	$("#maskBgDiv").css("height", $(document).height());
});